/**
 * <p>Title: TextToSummaryConverter.java</p>
 * <p>Description: DoNotes</p>
 * @author WangJun
 * @date 2009/11/29 23:56:03
 * @version 1.0
 */
package net.donotes.util.converter;

import java.util.Map;

import ognl.DefaultTypeConverter;

import com.google.appengine.api.datastore.Text;

/**
 * @author WangJun
 * 
 */
public class TextToSummaryConverter extends DefaultTypeConverter {
	@SuppressWarnings("unchecked")
	@Override
	public Object convertValue(Map map, Object obj, Class toType) {
		if (toType == Text.class) {
			String value = ((String[]) obj)[0];
			return new Text(value);
		} else if (toType == String.class) {
			Text text = (Text) obj;
			return text.getValue().split("\\[more..\\]")[0];
		}
		return null;
	}
}